package com.example.aicodehelper.AI;


import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.service.AiServices;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AiCodeHelperServiceFactory {

    @Resource
    private ChatModel qwenChatModel;


    @Bean
    public AiCodeHelperService aiCodeHelperService() {
//        会话记忆
        ChatMemory chatMemory = MessageWindowChatMemory.withMaxMessages(10);

//        return AiServices.create(AiCodeHelperService.class, qwenChatModel);
//        构造 AiService
        AiCodeHelperService aiCodeHelperService = AiServices.builder(AiCodeHelperService.class)
                .chatModel(qwenChatModel).chatMemory(chatMemory)
                .build();

        return aiCodeHelperService;

    }

}
